<template>
	<view class="main">
		<view class="my_center">
			<!-- 授权成功! -->
		</view>
	</view>
</template>

<script>
	import {
		authTwo
	} from '@/api/login.js'
	export default {
		data() {
			return {
				// timestamp: 5,
				// countHandle:''
			}
		},
		created() {
			this.initAuth()
		},
		methods: {
			async initAuth() {
				let handle = uni.getStorageSync('token')
				//console.log(token,'token');
				if (handle.token) { //有token就跳首页，没有就走登录流程。
					uni.switchTab({
						url: '/pages/index/index'
					});
					// uni.navigateTo({
					// 	url: '/pages/test/test'
					// });
					return
				}

				let res = await authTwo() //登录流程，这里的301跳转必须跳，才能拿到usercode
				if (res.code == 200) {
					uni.setStorageSync('redirect', res.data)
					//window.history.replaceState(null, "", res.data);
					window.location.href = res.data
					//window.history.go(0);
				}
				if (res.code == 500) {
					let twoRes = await authTwo()
					if (twoRes.code == 200) {
						uni.setStorageSync('redirect', twoRes.data)
						window.location.href = twoRes.data
					}
				}

			}
		},
	}
</script>

<style lang="scss" scoped>
	.main {

		//background-color: #F8F8F8;
		// width:375px;
		// height: 50vh;
		.my_center {
			font-size: 36rpx;
			//margin: 20px auto 0 auto;
		}
	}
</style>